import {getPosition} from "../../utils/positionData"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight:"",
    navBarHeight:"",
    makers:[],
    points:[],
    active:0,
    isShow:false,
    currentData:""
  },
  tapMap(e:any){
    console.log(e);
  },
  calloutTap(e:any){
    console.log(e);
    this.setData({
      isShow:true,
      currentData:this.data.makers[e.markerId]
    })
  },
  switchPosition(e:any){
    let id = e.currentTarget.dataset.nav
    let makers =  getPosition(id) as any
     let points = makers.map((item:any)=>{
      let point = {} as any
      point.latitude = item.latitude
      point.longitude = item.longitude
      return point;
    })
      this.setData({
        active:e.currentTarget.dataset.nav,
        makers,
        points
    })
  },
  toThis(){
   const {latitude,longitude,info} = this.data.currentData as any
    wx.openLocation({
      latitude,
      longitude,
      name:info.title
    }).then(_=>{      
      this.setData({
        isShow:false
      })   
    }).catch((err)=>{
      console.log(err);
    })
  },
  close(){
    this.setData({
      isShow:false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getTabBar().setData({
      active:1
    })
    const statusBarHeight = wx.getStorageSync("statusBarHeight");
    const navBarHeight = wx.getStorageSync("navBarHeight");
    this.setData({
      statusBarHeight,
      navBarHeight
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})